load detector
p =  struct('numofobject', 0, 'Appearance', [,], 'position', [,], 'scale', []);
first = true;



for i = 930:950
   
    indexi = i - 929;
    
    
    figure(2 * indexi - 1);
   % figure(2 * indexi);
    
    imagename = strcat('seq02-img-left/image_',  num2str(i,'%08d'), '_0.png');
    imagename_next = strcat('seq02-img-left/image_',  num2str(i + 1,'%08d'), '_0.png');
    im = imread(imagename);
    im_next  = imread(imagename_next);
    objectnum = detector(indexi).numofdetectors;
    p(indexi).numofobject = objectnum;
    Loc= detector(indexi).Location;
    for j=1:objectnum
        
        
        
        imagedata  = rgb2gray(im(round(Loc(j,2)):round(Loc(j,4)), round(Loc(j,1)):round(Loc(j,3)), :));
        %save strcat('imagedata_', num2str(i),'_', num2str(j));
       
        %curframe
        im1 = im2double(rgb2gray(im(round(Loc(j,2)):round(Loc(j,4)), round(Loc(j,1)):round(Loc(j,3)), :)));
        set(0, 'CurrentFigure', 2*indexi - 1);
        subplot(1, objectnum, j);
        
        imshow(im1);
        
        im2 = im2double(rgb2gray(im_next(round(Loc(j,2)):round(Loc(j,4)), round(Loc(j,1)):round(Loc(j,3)), :)));
    
        %figure(3);
        
        
      %  set(0, 'CurrentFigure', 2*indexi);
      %  subplot(1, objectnum, j);
       
        [u,v] = HierarchicalLK(im1, im2, 1, 3, 0, 0); 
        %[u, v, relaiable] = optFlowLk(im1, im2,[], 4, 1.2, 3e-6, 1);
       % p(indexi).Feature(j,:) = HistogramOfOpticalFlow(u, v, 360 ,20);
       
        p(indexi).Appearance(j,:) = OpticalFlowDescript1(u, v, 9 ,4);
       % p(indexi).Appearance(j,:) = anna_phog(im, 8, 360, 2, roi);
        p(indexi).Position(j,1) = (Loc(j,2) + Loc(j,4))/2;
        p(indexi).Position(j,2) = (Loc(j,1) + Loc(j,3))/2;
        p(indexi).Scale(j) = sqrt((Loc(j,4) - Loc(j,2)) * (Loc(j,3) - Loc(j,1)));
    end
    if ~first
        d = getDis(p(indexi-1), p(indexi), 'bhattacharyya')
    end
    first = false;
    disp(imagename);
    pause;
end
  

